package com.imachen.ymcc.web.controller;

import com.imachen.ymcc.dto.AlipayNotifyDto;
import com.imachen.ymcc.dto.ApplyDto;
import com.imachen.ymcc.result.JSONResult;
import com.imachen.ymcc.service.IPayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
@RequestMapping("/pay")
public class PayController {

    @Autowired
    private IPayService payService;

    @RequestMapping(value = "/checkPayOrder/{orderNo}",method = RequestMethod.GET)
    public JSONResult checkPayOrder(@PathVariable("orderNo")String orderNo){
        return payService.checkPayOrder(orderNo);
    }

    /**
     * 调用支付服务
     */
    @RequestMapping(value = "/apply",method = RequestMethod.POST)
    public JSONResult apply(@RequestBody @Valid ApplyDto applyDto){
        return JSONResult.success(payService.apply(applyDto));
    }


    /**
     * 支付宝异步回调
     */
    @RequestMapping(value = "/alipay/notify",method = RequestMethod.POST)
    public JSONResult alipayNotify(AlipayNotifyDto alipayNotifyDto){
        return JSONResult.success(payService.alipayNotify(alipayNotifyDto));
    }
}
